package cn.itsource.controller;

import cn.itsource.common.AjaxResult;
import cn.itsource.common.PageResult;
import cn.itsource.domain.TDepartment;
import cn.itsource.query.DepartmentQuery;
import cn.itsource.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Effect:
 * date: 2022/1/13 16:53
 *
 * @author wangyu
 * @since JDK 1.8
 */
@RestController
@Api(tags ="部门管理的核心接口 ")
@RequestMapping("/dept")
public class DepartmentController {
    @Autowired
    private IDepartmentService departmentService;


    @GetMapping("/findall")
    public List<TDepartment> findAll(){
        return departmentService.findAll();
    }

    @PostMapping("/pagelist")
    public PageResult<TDepartment> pageList(@RequestBody DepartmentQuery query){
        return departmentService.pageList(query);
    }

    @GetMapping("/delete")
    public AjaxResult deleteDeptById(Long id){
        return departmentService.deleteDeptById(id);

    }

    @GetMapping("/finddeptbyid")
    public TDepartment findDeptById(Long id){
        return departmentService.findDeptById(id);
    }

    @PostMapping("/updateandadd")
    public AjaxResult updateAndAdd(@RequestBody TDepartment form){

        if (form.getId() == null || "".equals(form.getId())){
            return departmentService.add(form);
        }else {
            return departmentService.update(form);
        }
    }

    @PostMapping("/batchdel")
    @ApiOperation("批量删除的接口")
    public AjaxResult bacthDel(@RequestBody List<Long> ids){
        return departmentService.batchDel(ids);
    }

    @GetMapping("/findtree")
    public List<TDepartment> findTree(){
        return departmentService.findTree();
    }


}



